const router=require('koa-router')();
const koaBody=require('koa-body');

router.get('/',async ctx=>{

    await ctx.render('login',{
        title:'Login'
    });
});


router.post('/',koaBody(),async ctx=>{
    let {body}=ctx.request;
    if(body.name&&body.password){
        let koa2User={
            id:1234567890,
            name:body.name,
            array:[1,2,3,4,5,6,7,8,9,10],
            object:{
                emial:'xx@xx.com',
                address:'SH China',
                age:20000
            },
            fn:function(){alert(1122)},
            reg:/\w+/,
            time:new Date(),
            bool:false,
            undefined:undefined,
            null:null,
            nan:NaN
        };
        console.log('stringify:',JSON.stringify(koa2User));
        ctx.session.koa2User=koa2User;
        ctx.redirect('/');
    }else{
        ctx.body='用户或密码错误';
    }
});
module.exports=router;